package com.woolink.per.sys.user.pojo;

import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.util.Assert;

import com.woolink.per.sys.security.service.CustomUserDetails;

/**
 * User entity. @author MyEclipse Persistence Tools
 */
public class User implements CustomUserDetails, java.io.Serializable
{
    private Integer userId;
    
    private String userAccount;
    
    private String userName;
    
    private String userPassword;
    
    private String userDesc;
    
    private Integer enabled;
    
    private Integer issys;
    
    private Set userRoles = new HashSet(0);
    
    // Property accessors
    
    private static SortedSet<GrantedAuthority> sortAuthorities(Collection<GrantedAuthority> authorities) {
        Assert.notNull(authorities, "Cannot pass a null GrantedAuthority collection");
        // Ensure array iteration order is predictable (as per UserDetails.getAuthorities() contract and SEC-717)
        SortedSet<GrantedAuthority> sortedAuthorities =
            new TreeSet<GrantedAuthority>(new AuthorityComparator());

        for (GrantedAuthority grantedAuthority : authorities) {
            Assert.notNull(grantedAuthority, "GrantedAuthority list cannot contain any null elements");
            sortedAuthorities.add(grantedAuthority);
        }

        return sortedAuthorities;
    }
    
    private static class AuthorityComparator implements Comparator<GrantedAuthority>, Serializable {
        public int compare(GrantedAuthority g1, GrantedAuthority g2) {
            // Neither should ever be null as each entry is checked before adding it to the set.
            // If the authority is null, it is a custom authority and should precede others.
            if (g2.getAuthority() == null) {
                return -1;
            }

            if (g1.getAuthority() == null) {
                return 1;
            }

            return g1.getAuthority().compareTo(g2.getAuthority());
        }
    }
    
    public Integer getUserId()
    {
        return this.userId;
    }
    
    public void setUserId(Integer userId)
    {
        this.userId = userId;
    }
    
    public String getUserAccount()
    {
        return this.userAccount;
    }
    
    public void setUserAccount(String userAccount)
    {
        this.userAccount = userAccount;
    }
    
    public String getUserName()
    {
        return this.userName;
    }
    
    public void setUserName(String userName)
    {
        this.userName = userName;
    }
    
    public String getUserPassword()
    {
        return this.userPassword;
    }
    
    public void setUserPassword(String userPassword)
    {
        this.userPassword = userPassword;
    }
    
    public String getUserDesc()
    {
        return this.userDesc;
    }
    
    public void setUserDesc(String userDesc)
    {
        this.userDesc = userDesc;
    }
    

    public Integer getIssys()
    {
        return this.issys;
    }
    
    public void setIssys(Integer issys)
    {
        this.issys = issys;
    }

    /**
     * @return Returns the userRoles.
     */
    public Set getUserRoles()
    {
        return userRoles;
    }

    /**
     * @param userRoles The userRoles to set.
     */
    public void setUserRoles(Set userRoles)
    {
        this.userRoles = userRoles;
    }

    @Override
    public Collection<GrantedAuthority> getAuthorities()
    {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public String getPassword()
    {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public String getUsername()
    {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public boolean isAccountNonExpired()
    {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean isAccountNonLocked()
    {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean isCredentialsNonExpired()
    {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean isEnabled()
    {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean getEnabled()
    {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public String getUserDept()
    {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public String getUserDuty()
    {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public String getSubSystem()
    {
        // TODO Auto-generated method stub
        return null;
    }

    /**
     * @param enabled The enabled to set.
     */
    public void setEnabled(Integer enabled)
    {
        this.enabled = enabled;
    }

    @Override
    public Set getSysUsersRoleses()
    {
        // TODO Auto-generated method stub
        return null;
    }
    
}